package com.wubotao.multithreading;

public class Wait {
	public static void main(String[] args) {
		Calc calc = new Calc();
		calc.start();
		
		synchronized (calc) {
			try {
				System.out.println("Waiting for b to complete...");
				calc.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			System.out.println("Total is: " + calc.total);
		}
	}
}

class Calc extends Thread {
	int total;

	@Override
	public void run() {
		
		synchronized (this) {
			
			for (int i = 0; i < 100; i++) {
				total += i;
			}
			
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			notify();
		}
	}
}
